#include<iostream>
#include<string>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<windows.h>
#pragma GCC optimize("Ofast,no-stack-protector")
typedef unsigned long long int64;
int linesOfScreen, comOfScreen;
void clearScreen() {
	system("cls");
}
void showNewLine(int comment) {
	std::string temp = std::to_string(comment);
	for (int64 i = 0; i < temp.size(); i++) {
		putchar(temp[i]);
	}
}
void showNewLine(char comment) {
	putchar(comment);
}
void showNewLine(char* comment) {
	for (int i = 0; i < strlen(comment); i++) {
		putchar(comment[i]);
	}
}
void showNewLine(const char* comment) {
	std::string temp;
	temp = comment;
	for (int64 i = 0; i < temp.size(); i++) {
		putchar(temp[i]);
	}
}
void showNewLine(std::string comment) {
	for (int64 i = 0; i < comment.size(); i++) {
		putchar(comment[i]);
	}
}
void flushScreen(int showedLines) {
	for (int i = 0; i < linesOfScreen - showedLines; i++) {
		showNewLine('\n');
	}
}
void outputEmptyLines(int linesNum) {
	for (int i = 0; i < linesNum; i++) {
		showNewLine('\n');
	}
}
void wait(long double time) {
	usleep(time * 1000000.0);
}
int main() {
	using namespace std;
	cin >> linesOfScreen >> comOfScreen;
	showNewLine("WELCOME TO------");
	wait(1);
	clearScreen();
	showNewLine("Transport Simulator!");
	wait(3);
	clearScreen();
	int beepFrequency = 1000, beepTime = 500;
	bool isExit = false, isInSettingMode = false, isGameEnd = false;
	bool isTurnEndBeep = false;
	while (true) {
		clearScreen();
		char choose;
		showNewLine("Transport Simulator\n");
		showNewLine("(S)tart\n");
		showNewLine("S(e)ttings\n");
		showNewLine("E(x)it\n");
		showNewLine("\n\nInput you choose:___\b\b\b\a");
		cin >> choose;
		if (int(choose) > 'a') {
			choose -= 32;
		}
		switch (int(choose)) {
			case int('S'):
				while (!isGameEnd) {

					Beep(beepFrequency, beepTime);
				}
				break;
			case int('E'):
				isInSettingMode = true;
				break;
			case int('X'):
				isExit = true;
				break;
			default:
				showNewLine("Wrong Input.\n\a");
				wait(1);
				break;
		}
		if (isExit) {
			showNewLine("MANUALLY EXIT.\n\a");
			break;
		}
		if (isInSettingMode) {
			{
				int choose;
				showNewLine("SETTINGS:\n");
				showNewLine("-2.Show your settings\n");
				showNewLine("-1.Load settings file\n");
				showNewLine("0.Save settings\n");
				showNewLine("1.Will game beep when the end of a turn comes?\n");
				showNewLine("2.Beep's frequency and time?\n");
				showNewLine("10.Exit\n");
				cin >> choose;
				if (choose == -2) {
					showNewLine(isTurnEndBeep);
					showNewLine('\n');
					showNewLine(beepFrequency);
					showNewLine('\n');
					showNewLine(beepTime);
					showNewLine('\n');
					showNewLine("0.1.1");
				} else if (choose == -1) {
					FILE* fpi;
					fpi = fopen("TS.SETTINGS", "r");
					char temp[1024];
					int endOfTemp;
					memset(temp, 0, sizeof temp);
					fscanf(fpi, "%s", &temp);
					printf("Settings will load:%s\n", temp);
					for (int i = 0; i < 1024; i++) {
						if (int(temp[i]) == 0) {
							endOfTemp = i;
							break;
						}
					}
					string settingFileVersion;
					for (int i = endOfTemp - 5; i < endOfTemp; i++) {
						settingFileVersion.push_back(temp[i]);
					}
					if (settingFileVersion != "0.1.1") {
						showNewLine("This file is not for this version!\n");
					}
					isTurnEndBeep = temp[0] - '0';
					string temp1;
					for (int i = 2; temp[i] != '|'; i++) {
						temp1.push_back(temp[i]);
					}
					int64 frequencySize = temp1.size();
					beepFrequency = stoi(temp1);
					temp1 = "";
					for (int i = 3 + frequencySize; temp[i] != '|'; i++) {
						temp1.push_back(temp[i]);
					}
					beepTime = stoi(temp1);
					fclose(fpi);
				} else if (choose == 0) {
					FILE* fpo;
					fpo = fopen("TS.SETTINGS", "w");
					fprintf(fpo, "%d|%d|%d|0.1.1", isTurnEndBeep, beepFrequency, beepTime);
					fclose(fpo);
				} else if (choose == 1) {
					isTurnEndBeep = !isTurnEndBeep;
				} else if (choose == 2) {
					scanf("%d %d", &beepFrequency, &beepTime);
					showNewLine("\n");
				} else if (choose == 10) {
					showNewLine("Exit and apply changes...\n");
				} else {
					showNewLine("Wrong Input\n");
				}
			}
		}
		wait(2 + 1453 - 1453);
	}
	return 0;
}
